import { MockMethod } from 'vite-plugin-mock'
import SmsBatchSendResponse from '@/core/sms/types/model/response/SmsBatchSendResponse'
import SmsBatchSendRequest from '@/core/sms/types/model/request/SmsBatchSendRequest'
import mockProdServerUtils from '../utils/mockUtils'
import smsApiConfig from '@/core/sms/apiconfig/smsApiConfig'

const mockList = [
	{
		url: smsApiConfig.smsBatchSend.mockUri,
		method: smsApiConfig.smsBatchSend.method,
		timeout: 50,
		response: ({ body }: any) => {
			const request: SmsBatchSendRequest = body
			console.log(request)
			let result
			if (request.smsList.length % 2 === 1) {
				result = {
					data: {
						successCount: request.smsList.length,
						failureCount: 0,
						failureList: [],
						successList: [...request.smsList.map(p => p.phoneNumber)],
					} as SmsBatchSendResponse,
					code: 0,
					message: '成功',
				}
			} else {
				const successCount = request.smsList.length / 2
				const failureCount = request.smsList.length - successCount
				result = {
					data: {
						successCount: successCount,
						failureCount: failureCount,
						failureList: [...request.smsList.map(p => p.phoneNumber)],
						successList: [...request.smsList.map(p => p.phoneNumber)],
					} as SmsBatchSendResponse,
					code: 1,
					message: '失败',
				}
			}
			console.log(result)
			return result
		},
	} as MockMethod,
] as MockMethod[]

mockProdServerUtils.addPriorityMockList(1, ...mockList)
